package com.qtz.demo.controller;

import com.qtz.demo.bean.Question;
import com.qtz.demo.service.QuestionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionServiceImpl questionService;

    //添加问题
    @RequestMapping(value = "/addQuestion",method = RequestMethod.POST)
    @ResponseBody
    public boolean addOrder(@RequestBody Map<String,String> map){

        String current = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( new Date());
        Timestamp time = Timestamp.valueOf(current);

        Question question = new Question();
        question.setOid(map.get("oid"));
        question.setUid(map.get("uid"));
        question.setQuestion(map.get("question"));
        question.setCreatetime(time);

        System.out.println(question);


        return questionService.addQuestion(question);
    }

    //显示所有QA记录
    @RequestMapping(value = "/showQA/{oid}",method = RequestMethod.GET)
    @ResponseBody
    public List<Map> showQA(@PathVariable("oid") String oid){
        return questionService.showQA(oid);
    }

    //显示当前订单未处理问题
    @RequestMapping(value = "/showUndoQuestion/{oid}",method = RequestMethod.GET)
    @ResponseBody
    public List<Question> showUndoQuestion(@PathVariable("oid") String oid){
        return questionService.showUndoQuestion(oid);
    }
}
